package com.thinkfit.jy.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.common.lib.bean.UserBean;
import com.common.lib.constant.Constants;
import com.common.lib.fragment.BaseFragment;
import com.common.lib.manager.DataManager;
import com.common.lib.mvp.contract.EmptyContract;
import com.common.lib.mvp.presenter.EmptyPresenter;
import com.common.lib.utils.BaseUtils;
import com.thinkfit.jy.R;
import com.thinkfit.jy.activity.SettingNewOtherActivity;

/**
 * 用户数据信息
 */
public class PersonalDataFragment extends BaseFragment<EmptyContract.Presenter> implements EmptyContract.View {

    private UserProfileFragment mUserProfileFragment;
    ImageView ivAvatar;
    @NonNull
    @Override
    protected EmptyContract.Presenter onCreatePresenter() {
        return new EmptyPresenter(this);
    }

    @Override
    protected int getLayoutId() {
//        return DataManager.Companion.getInstance().getMainStyle() == 3 ? R.layout.fragment_personal_data_xm : R.layout.fragment_personal_data;
        return R.layout.fragment_personal_data_new;
    }

    @Override
    protected void initView(@NonNull View view, @Nullable Bundle savedInstanceState) {
        setViewsOnClickListener(R.id.llNick, R.id.llBirthday, R.id.llGender, R.id.llHeight, R.id.llWeight);
        ivAvatar = view.findViewById(R.id.ivAvatar);
    }

    @Override
    public void onResume() {
        super.onResume();
        showUserInfo();
    }

    private void showUserInfo() {
        UserBean myInfo = DataManager.Companion.getInstance().getMyInfo();
        setText(R.id.tvNick, myInfo.getNickname());
        setText(R.id.tvGender, myInfo.getSex() == 1 ? R.string.app_male : R.string.app_female);
        setText(R.id.tvBirthday, myInfo.getBirthday());
        setText(R.id.tvHeight, myInfo.getHeight() + "cm");
        setText(R.id.tvWeight, myInfo.getWeight() + "kg");
        BaseUtils.StaticParams.loadImage(getContext(), R.drawable.app_not_login, myInfo.getHeadimg(),ivAvatar);
    }

    public PersonalDataFragment setParentFragment(UserProfileFragment fragment) {
        mUserProfileFragment = fragment;
        return this;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.llNick:
                Bundle bundle = new Bundle();
                bundle.putInt(Constants.BUNDLE_EXTRA,SettingNewOtherActivity.NICKNAME);
                openActivity(SettingNewOtherActivity.class,bundle);
//                mUserProfileFragment.toFragment(new UpdateNickFragment());
                break;
            case R.id.llBirthday:
                bundle = new Bundle();
                bundle.putInt(Constants.BUNDLE_EXTRA,SettingNewOtherActivity.BIRTHDAY);
                openActivity(SettingNewOtherActivity.class,bundle);
//                mUserProfileFragment.toFragment(new ChooseBirthdayFragment());
                break;
            case R.id.llGender:
                bundle = new Bundle();
                bundle.putInt(Constants.BUNDLE_EXTRA,SettingNewOtherActivity.CHOOSE_GENDER);
                openActivity(SettingNewOtherActivity.class,bundle);
//                mUserProfileFragment.toFragment(new ChooseGenderFragment());
                break;
            case R.id.llHeight:
                bundle = new Bundle();
                bundle.putInt(Constants.BUNDLE_EXTRA,SettingNewOtherActivity.HEIGHT);
                openActivity(SettingNewOtherActivity.class,bundle);
//                mUserProfileFragment.toFragment(new ChooseHeightFragment());
                break;
            case R.id.llWeight:
                bundle = new Bundle();
                bundle.putInt(Constants.BUNDLE_EXTRA,SettingNewOtherActivity.WEIGHT);
                openActivity(SettingNewOtherActivity.class,bundle);
//                mUserProfileFragment.toFragment(new ChooseWeightFragment());
                break;
        }
    }
}
